import java.io.*;
import java.net.Socket;

public class ChatChannel extends Thread{
    Socket socket;

    public ChatChannel(Socket socket){
        this.socket= socket;
    }

    @Override
    public void run() {

        try {
            InputStream in =socket.getInputStream();
            //封装成高级的输入流
            ObjectInputStream ois = new ObjectInputStream(in);
            String name = (String) ois.readObject();
            System.out.println(name + "进入聊天室");
            //返回给客户端欢迎信息，用到输出流对象
            OutputStream os = socket.getOutputStream();
            //封装成高级的对象输出流
            ObjectOutputStream oos = new ObjectOutputStream(os);
            oos.writeObject("欢迎您，" + name);
        } catch (IOException e) {
            throw new RuntimeException(e);
        } catch (ClassNotFoundException e) {
            throw new RuntimeException(e);
        }


    }
}
